-
Notifications
You must be signed in to change notification settings - Fork 279
Update variable replacement during deserialization to use replacement settings class and add AKV replacement logic. #2882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
// Determines whether to replace environment variable with its | ||
// value or not while deserializing. | ||
private bool _replaceEnvVar; | ||
// Settings for variable replacement during deserialization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe make the comment a bit more descriptive, to show that it can replace the variable with either AKV, an environment variable, or nothing during deserialization.
// Determines whether to replace environment variable with its | ||
// value or not while deserializing. | ||
private bool _replaceEnvVar; | ||
// Settings for variable replacement during deserialization. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as comment above, this applies to all the places where the variable type was changed
/// <param name="replaceEnvVar">Whether to replace environment variable with its | ||
/// value or not while deserializing.</param> | ||
internal EntityCacheOptionsConverterFactory(bool replaceEnvVar) | ||
internal EntityCacheOptionsConverterFactory(DeserializationVariableReplacementSettings? replacementSettings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The param name
comment should also be changed.
/// <param name="replaceEnvVar">Whether to replace environment variable with its | ||
/// value or not while deserializing.</param> | ||
public EntityCacheOptionsConverter(bool replaceEnvVar) | ||
public EntityCacheOptionsConverter(DeserializationVariableReplacementSettings? replacementSettings) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The param name
comment should also be changed.
foreach (KeyValuePair<Regex, Func<Match, string>> strategy in _replacementSettings.ReplacementStrategies) | ||
{ | ||
value = strategy.Key.Replace(value, new MatchEvaluator(strategy.Value)); | ||
} | ||
|
||
return value; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am confused with how this section works, wouldn't this just give you the last replacement strategy since they are all saved in the same value?
|
||
if (!string.IsNullOrEmpty(json) && TryParseConfig(json, out RuntimeConfig, connectionString: _connectionString, replaceEnvVar: replaceEnvVar)) | ||
if (!string.IsNullOrEmpty(json) && TryParseConfig(json, out RuntimeConfig, | ||
new DeserializationVariableReplacementSettings(azureKeyVaultOptions: null, doReplaceEnvVar: true, doReplaceAKVVar: true), logger: null, connectionString: _connectionString)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to delete the parameter replaceEnvVar
from the TryLoadConfig
function since we don't use it anymore
// Add environment variable replacement if enabled | ||
if (enableEnvReplacement) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume that there must be something missing inside this if
Why make this change?
Adds AKV variable replacement and expands our design for doing variable replacements to be more extensible when new variable replacement logic is added.
Closes #2708
Closes #2748
Related to #2863
What is this change?
Change the way that variable replacement is handled to instead of simply using a
bool
to indicate that we want env variable replacement, we add a class which holds all of the replacement settings. This will hold whether or not we will do replacement for each kind of variable that we will handle replacement for during deserialization. We also include the replacement failure mode, and put the logic for handling the replacements into a strategy dictionary which pairs the replacement variable type with the strategy for doing that replacement.Because Azure Key Vault secret replacement requires having the retry and connection settings in order to do the AKV replacement, we must do a first pass where we only do non-AKV replacement and get the required settings so that if AKV replacement is used we have the required settings to do that replacement.
We also have to keep in mind that the legacy of the
Configuration Controller
will ignore all variable replacement, so we construct the replacement settings for this code path to not use any variable replacement at all.How was this tested?
We have updated the logic for the tests to use the new system, however manual testing using an actual AKV is still required.
Sample Request(s)